﻿using CommunityToolkit.Mvvm.ComponentModel;
using MT.CustomUserControl.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;

namespace MT.CustomUserControl.ViewModels
{
    public class ChronicUcViewModel:ObservableObject
    {
        /// <summary>
        /// 慢性病,无女性症状
        /// </summary>
        private List<string> ChronicManList = new List<string> { "偏头痛", "过敏性鼻炎", "慢性鼻炎", "黄斑变性", "干眼症", "慢性咽炎", "牙周炎", "甲状腺功能亢进",
                                                    "甲状腺功能减退", "哮喘", "慢性支气管炎", "慢性阻塞性肺疾病", "高血压", "冠心病", "房颤", "心功能不全", "心脏瓣膜病", "慢性胃炎",
                                                    "消化性溃疡", "肠易激惹综合征", "脂肪肝", "慢性乙型肝炎", "肝硬化", "胆结石", "肾病综合征", "慢性肾炎", "慢性肾功能不全", "泌尿系结石",
                                                    "风湿性关节炎", "骨质疏松症", "骨质增生", "颈椎病", "腰椎管狭窄", "腰椎间盘突出", "坐骨神经痛", "肩周炎", "糖尿病", "高脂血症",
                                                    "痛风", "慢性贫血", "中风后遗症", "荨麻疹", "湿疹", "抑郁症", "焦虑症"  };

        /// <summary>
        /// 慢性病，带有女性症状
        /// </summary>

        private List<string> ChronicAllList = new List<string> { "偏头痛", "过敏性鼻炎", "慢性鼻炎", "黄斑变性", "干眼症", "慢性咽炎", "牙周炎", "甲状腺功能亢进",
                                                    "甲状腺功能减退", "哮喘", "慢性支气管炎", "慢性阻塞性肺疾病", "高血压", "冠心病", "房颤", "心功能不全", "心脏瓣膜病", "慢性胃炎",
                                                    "消化性溃疡", "肠易激惹综合征", "脂肪肝", "慢性乙型肝炎", "肝硬化", "胆结石", "肾病综合征", "慢性肾炎", "慢性肾功能不全", "泌尿系结石",
                                                    "风湿性关节炎", "骨质疏松症", "骨质增生", "颈椎病", "腰椎管狭窄", "腰椎间盘突出", "坐骨神经痛", "肩周炎", "糖尿病", "高脂血症",
                                                    "痛风", "慢性贫血", "中风后遗症", "更年期综合征", "月经不调", "乳腺增生", "荨麻疹", "湿疹", "抑郁症", "焦虑症"  };

        public List<ChronicModel> ChronicDiseaseList = new List<ChronicModel>();

        /// <summary>
        /// 慢性病显示集合
        /// </summary>
        private ObservableCollection<ChronicModel> chronicDiseases = new ObservableCollection<ChronicModel>();
        public ObservableCollection<ChronicModel> ChronicDiseases
        {
            get { return chronicDiseases; }
            set { SetProperty(ref chronicDiseases, value); }
        }

        /// <summary>
        /// 选中的慢性病
        /// </summary>
        private ObservableCollection<ExtendSelectedItemMdoel> selectedChronicList = new ObservableCollection<ExtendSelectedItemMdoel>();
        public ObservableCollection<ExtendSelectedItemMdoel> SelectedChronicList
        {
            get { return selectedChronicList; }
            set { SetProperty(ref selectedChronicList, value); }
        }

        public Action SelectedChronicListChangedAction;

        /// <summary>
        /// 慢性病列表是否可见
        /// </summary>
        private Visibility chronicListVisibility = Visibility.Collapsed;
        public Visibility ChronicListVisibility
        {
            get { return chronicListVisibility; }
            set { SetProperty(ref chronicListVisibility, value); }
        }

        /// <summary>
        /// 已选的慢性病列表是否可见
        /// </summary>
        private Visibility selectedChronicVisibility = Visibility.Collapsed;
        public Visibility SelectedChronicVisibility
        {
            get { return selectedChronicVisibility; }
            set { SetProperty(ref selectedChronicVisibility, value); }
        }

        public ChronicUcViewModel()
        {
            
        }

        public void SetChronicDiseasesSourceByGender(string gender)
        {
            ChronicDiseaseList.Clear();
            if (gender == "男")
            {
                foreach (var chronic in ChronicManList)
                {
                    ChronicModel chronicModel = new ChronicModel();
                    chronicModel.Name = chronic;
                    chronicModel.ShortName = ToolBoxHelper.GetFirstCode(chronic);
                    ChronicDiseaseList.Add(chronicModel);
                }
            }
            else
            {
                foreach (var chronic in ChronicAllList)
                {
                    ChronicModel chronicModel = new ChronicModel();
                    chronicModel.Name = chronic;
                    chronicModel.ShortName = ToolBoxHelper.GetFirstCode(chronic);
                    ChronicDiseaseList.Add(chronicModel);
                }
            }
        }

        public void SetCurSelectedChronicDiseases(string chronicDiseases)
        {
            SelectedChronicList.Clear();
            string[] tempDiseases = chronicDiseases.Split('-');
            foreach (var chronicName in tempDiseases)
            {
                if (string.IsNullOrEmpty(chronicName))
                    continue;

                ExtendSelectedItemMdoel extendSelectedItemMdoel = new ExtendSelectedItemMdoel();
                extendSelectedItemMdoel.ItemContent = chronicName;
                extendSelectedItemMdoel.DeleteAction = DeleteSelectedChronicActionFunc;
                SelectedChronicList.Add(extendSelectedItemMdoel);
            }

            if (SelectedChronicList.Count > 0)
                SelectedChronicVisibility = Visibility.Visible;
            else
                SelectedChronicVisibility = Visibility.Collapsed;
        }


        public void DeleteSelectedChronicActionFunc(ExtendSelectedItemMdoel model)
        {
            if (SelectedChronicList.Contains(model))
            {
                SelectedChronicList.Remove(model);

                var tempList = ChronicDiseases.Where(temp => temp.Name == model.ItemContent).ToList();
                if (tempList.Count == 1)
                {
                    tempList[0].SelectedState = false;
                }

                SelectedChronicListChangedAction?.Invoke();
            }

            if (SelectedChronicList.Count > 0)
                SelectedChronicVisibility = Visibility.Visible;
            else
                SelectedChronicVisibility = Visibility.Collapsed;
        }
    }
}
